package com.xyzyzglxt.web.controller.volunteer;

import com.xyzyzglxt.common.annotation.Log;
import com.xyzyzglxt.common.core.controller.BaseController;
import com.xyzyzglxt.common.core.domain.AjaxResult;
import com.xyzyzglxt.system.domain.SysEvent;
import com.xyzyzglxt.common.core.page.TableDataInfo;
import com.xyzyzglxt.common.enums.BusinessType;
import com.xyzyzglxt.system.service.ISysEventService;
import com.xyzyzglxt.system.service.ISysUserEventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;



/**
 * 活动信息Controller
 *
 * @author xyzyzglxt
 * @date 2022-01-17
 */
@Api(tags = "活动展示")
@RestController
@RequestMapping("/volunteer/show")
public class SysEventShowController extends BaseController {

    @Autowired
    private ISysEventService sysEventService;

    @Autowired
    private ISysUserEventService sysUserEventService;

    /**
     * 查询已审核的活动信息
     */
    @ApiOperation("查询已审核的活动信息")
    @PreAuthorize("@ss.hasPermi('volunteer:show:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysEvent sysEvent)
    {
        startPage();
        List<SysEvent> list = sysEventService.selectCheckSysEventList(sysEvent);
        return getDataTable(list);
    }


    /**
     * 活动报名
     */
    @ApiOperation("活动报名")
    @PreAuthorize("@ss.hasPermi('volunteer:show:report')")
    @Log(title = "活动报名", businessType = BusinessType.INSERT)
    @PostMapping("/report")
    public AjaxResult report(@RequestBody SysEvent sysEvent) {

        int num = sysUserEventService.reportSysUserEvent(sysEvent.getEventUserId(), sysEvent.getEventId());
        if (num == -1) {
            return error("活动未审核");
        }else if (num == 0){
            return error("报名人数已满");
        }else if(num == -2){
            return error("活动已开始或已结束");
        }else if(num == -3){
            return error("你已报名");
        }
        return success();
    }

}
